package cn.edu.sdjzu.xg.eagle.service.impl;//package cn.edu.sdjzu.xg.bysj.service;

import cn.edu.sdjzu.xg.eagle.dao.ResourceDao;
import cn.edu.sdjzu.xg.eagle.entity.authority.Permission;
import cn.edu.sdjzu.xg.eagle.factory.DaoFactory;
import cn.edu.sdjzu.xg.eagle.service.ResourceService;
import cn.edu.sdjzu.xg.eagle.util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;

//
//
//import cn.edu.sdjzu.xg.bysj.dao.ResourceDaoImpl;
//import cn.edu.sdjzu.xg.bysj.entity.authority.Permission;
//import cn.edu.sdjzu.xg.bysj.exception.BysjException;
//
//import cn.edu.sdjzu.xg.bysj.util.Condition;
//import cn.edu.sdjzu.xg.bysj.util.JdbcHelper;
//import cn.edu.sdjzu.xg.bysj.util.Pagination;
//
//
//import java.sql.Connection;
//import java.sql.SQLException;
//import java.sql.SQLIntegrityConstraintViolationException;
//import java.util.Collection;
//import java.util.List;
//
public final class ResourceServiceImpl implements ResourceService {
	private static final ResourceDao resourceDao = DaoFactory.getDao(ResourceDao.class, "ResourceDaoImpl");

	@Override
	public Collection<Permission> findAll(Integer roleId) throws SQLException {
		//获取数据库连接
		Connection connection = JdbcHelper.getConn();
		Collection<Permission> resources = resourceDao.findAll(connection, roleId);
		//释放连接
		JdbcHelper.close(connection);
		return resources;
	}

//	public Collection<Permission> findAll(Pagination pagination, List<Condition> conditionList) throws SQLException {
//		//获取数据库连接
//		Connection connection = JdbcHelper.getConn();
//		Collection<Permission> resources = resourceDao.findAll(connection, pagination, conditionList);
//		//释放连接
//		JdbcHelper.close(connection);
//		return resources;
//
//	}

	@Override
	public Permission find(Integer id) throws SQLException {
		//获取数据库连接
		Connection connection = JdbcHelper.getConn();
		Permission resource = resourceDao.find(connection, id);
		//释放连接
		JdbcHelper.close(connection);
		return resource;
	}

//	public boolean update(Permission resource) throws SQLException {
//		//获取数据库连接
//		Connection connection = JdbcHelper.getConn();
//		boolean updated = resourceDao.update(connection, resource);
//		//释放连接
//		JdbcHelper.close(connection);
//		return updated;
//	}
//
//	public boolean add(Permission resource) throws SQLException {
//		Connection connection = JdbcHelper.getConn();
//		boolean added = resourceDao.add(connection, resource);
//		JdbcHelper.close(connection);
//		return added;
//	}
//
//	public boolean delete(Integer id) throws SQLException, BysjException {
//		//获取数据库连接
//		Connection connection = JdbcHelper.getConn();
//		boolean deleted = false;
//		try {
//			deleted = resourceDao.delete(connection, id);
//			return deleted;
//		} catch (SQLIntegrityConstraintViolationException e) {
//			throw new BysjException("某角色正在使用当前资源");
//		} finally {
//			//释放连接
//			JdbcHelper.close(connection);
//		}
//	}
}
